//
//  BKJH5ViewController.m
//  BKJ
//
//  Created by 贝壳家iOS on 15/11/19.
//  Copyright © 2015年 贝壳家iOS. All rights reserved.
//

#import "BKJH5ViewController.h"
#import <WebKit/WebKit.h>






@interface BKJH5ViewController ()
@property (nonatomic, strong)WKWebView *webView;
@property (nonatomic, strong)	UIProgressView *progressView;
//@property (nonatomic, strong)UIButton *dissmissButton;
@end

@implementation BKJH5ViewController

#pragma mark - life

- (void)viewWillAppear:(BOOL)animated{
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
  [self.view addSubview:self.webView];
	[self.view addSubview:self.progressView];
	[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.width.equalTo(self.view);
		make.top.equalTo(self.mas_topLayoutGuideBottom);
	}];
    [self addMethod];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - method
- (void)addMethod{
	[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.h5Url]]];

	@weakify(self);
	
	[RACObserve(self.webView, estimatedProgress) subscribeNext:^(NSNumber *x) {
		@strongify(self)
		self.progressView.progress = [x floatValue];
		if ([x floatValue] == 1) {
			self.progressView.progressTintColor = [UIColor whiteColor];
		}
	}];


}

#pragma mark - events


#pragma mark - setter&getter
- (WKWebView *)webView{
    if (_webView == nil) {
        _webView = [[WKWebView alloc] initWithFrame:self.view.bounds];
    }
    return _webView;
}
- (UIProgressView *)progressView{
	if (!_progressView) {
		_progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
		_progressView.progressTintColor = SLYellowColor;
		_progressView.trackTintColor = [UIColor lightGrayColor];
	}
	return _progressView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
